<div class="row">    
    <div class="col-lg-12">
        <h3 class="page-header">Danh sách sản phẩm</h3>
    </div>
    <!-- /.col-lg-12 -->
</div>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
             <div class="panel-heading">
                 <a class="" href="<?php echo $this->url(array("action"=>"add")) ?>">Thêm sản phẩm</a>
            </div>
            <div class="panel-body">                
                <div class="table-reponsive">
                    <div id="jqxgrid">                                
                    </div>
                </div>
        </div>
    </div>
</div>
<script type="text/javascript">
        $(document).ready(function () {
            // prepare the data
            var source =
            {
                datatype: "json",
                datafields:
                [
                    { name: 'id',type:'int'},
                    { name: 'name', type: 'string' },                    
                    { name: 'product_cat_id', type: 'string' },
                    { name: 'order', type: 'int' },
                    { name: 'status', type: 'string' }
                ],
                url:"<?php echo $this->baseUrl().'/admin/product/service' ?>",
                sortcolumn: 'Order',
                sortdirection: 'asc'               
            };
         var dataAdapter = new $.jqx.dataAdapter(source, {
                loadComplete: function () {
                }
            });
            $("#jqxgrid").jqxGrid(
            {
                width: '100%',
                source: dataAdapter,  
                theme: 'bootstrap',
                pageable: true,
                showfilterrow: true,
                filterable: true,
                autoheight: true,
                sortable: true,
                altrows: true,
                enabletooltips: true,
                selectionmode: 'multiplecellsadvanced',
                columnsResize: true,
                rendergridrows: function (params) {
                    return params.data;
                },
                ready: function () {
                    $("#jqxgrid").jqxGrid('hideColumn', 'id');
                },
                columns: [
                  {text:  'id',dataField:'id',cellsAlign:'right',width:0},
                  { text: 'Tên sản phẩm',editable: false, dataField: 'name', width: '45%' },                 
                  { text: 'Loại sản phẩm',editable: false, dataField: 'product_cat_id', width: '30%' },
                  { text: 'Thứ tự',editable: false, dataField: 'order', width: '10%' } , 
                  { text: 'Hiển thị',columnType:'checkbox', editable: false, dataField: 'status', width: '5%' },                   
                  {text: 'Xoá',filtertype: 'none',width:'5%', cellsalign: 'right', align: "center", columnType: 'none', editable: false, sortable: false, dataField: null, cellsrenderer: function (row) {
                          // render custom column.
                          editrow = row;
                          var dataRecord = $("#jqxgrid").jqxGrid('getrowdata',editrow);
                          var url= "<div style='overflow: hidden; text-overflow: ellipsis; padding-bottom: 2px; text-align: center; margin-right: 2px; margin-left: 4px; margin-top: 4px;'><a class='fa fa-trash-o fa-lg'";
                          url = url + "href='#' onclick='return jsdelete("+dataRecord.id+")'></a></div>";
                          return url;
                      }
                          },
                    {text: 'Sửa',filtertype: 'none',width:'5%', cellsalign: 'right', align: "center", columnType: 'none', editable: false, sortable: false, dataField: null, cellsrenderer: function (row) {
                          // render custom column.
                          editrow = row;
                          var dataRecord = $("#jqxgrid").jqxGrid('getrowdata',editrow);
                          var url= "<div style='overflow: hidden; text-overflow: ellipsis; padding-bottom: 2px; text-align: center; margin-right: 2px; margin-left: 4px; margin-top: 4px;'><a class='fa fa-edit fa-lg'";
                          url = url + "href='<?php echo $this->baseUrl()?>/admin/product/edit/id/"+dataRecord.id+"'></a></div>";
                          return url;
                      }
                          }
                ]
            });
           
        });
    </script>
    <script type="text/javascript">
        function jsdelete(id)
        {
            bootbox.confirm("Bạn có chắc muốn xoá sản phẩm này?",function(result){
                if(result==true)
                    window.location = "<?php echo $this->baseUrl() ?>/admin/product/delete/id/"+id;
            });
        }
    </script>